from flask import Flask
from mongoengine import connect

from before_request import set_before_request
from setting import Config
from user import user_bp
from operation_trajectory.view import operation_trajectory_bp

config = Config()
app = Flask(__name__)
app.config.from_object(config)

# 读取配置文件
print(app.config)

# 连接数据库
connect(host=config.MONGO_HOST_URL)

# 钩子
set_before_request(app)
# 注册蓝图
app.register_blueprint(user_bp, url_prefix='/api/v1.0/user')
app.register_blueprint(operation_trajectory_bp,
                       url_prefix='/api/v1.0/operation_trajectory')

if __name__ == '__main__':
    # websocket
    app.run(port=config.PORT, host='0.0.0.0')
